package org.karelun.gef.figure;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class ActorFigure extends NodeFigure {

    private class ActorShape extends Shape{
		public ActorShape(){
			
		}
		protected void fillShape(Graphics graphics) {
			Rectangle full = this.getBounds();	
			int r=Math.min(full.height/6,full.width/2);
			int midX=full.x+full.width/2;
			
			Rectangle top=new Rectangle(midX-r,full.y,r*2,r*2);
			graphics.drawOval(top);
			
//			graphics.drawLine(midX, full.y+r*2, midX, full.y+r*4);// |
//			graphics.drawLine(midX-r,full.y+r*3, midX+r, full.y+r*3);// -
//			graphics.drawLine(midX, full.y+r*4, midX-r, full.y+r*6); //  /
//			graphics.drawLine(midX, full.y+r*4, midX+r, full.y+r*6); //    \
			
			graphics.drawLine(midX, full.y+r*2, midX, full.y+r*4);// |
			graphics.drawLine(midX-r,full.y+r*5/2, midX+r, full.y+r*5/2);// -
			
			graphics.drawLine(midX, full.y+r*4, midX-r, full.y+r*6); //  /
			graphics.drawLine(midX, full.y+r*4, midX+r, full.y+r*6); //    \
		}
		
		protected void outlineShape(Graphics graphics) {
		}
	}
    
    private ActorShape actor=null;
    
	public ActorFigure() {
		super();
	    BorderLayout layout = new BorderLayout();
		setLayoutManager(layout);
		
		actor= new ActorShape();
		label=new Label();
		actor.add(label);
		add(actor,BorderLayout.CENTER);
		
		setOpaque(true);
	}

    public void setBounds(Rectangle rect) {
        super.setBounds(rect);
        this.label.setBounds(rect);
    }

	@Override
	protected void setBGColor(Color color) {
		if(actor==null)
			return;
		actor.setForegroundColor(color);
	}
}